package cn.ncist.controller;


import cn.ncist.common.RespResult;
import cn.ncist.constant.MessageConstant;
import cn.ncist.health_interface.service.SetMealService;
import cn.ncist.pojo.Setmeal;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @DubboReference
    private SetMealService setMealService;

    @PostMapping("/getSetmeal")
    public RespResult getSetmeal(){
        try {
            List<Setmeal> setmealList = setMealService.findAll();
            return new RespResult(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new RespResult(false, MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }

    @GetMapping("/findById")
    public RespResult findById(Integer id){
        try {
            Setmeal setmeal = setMealService.findById(id);
            return new RespResult(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new RespResult(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
